package com.usian.controller;

import com.usian.feign.ContentServiceFeign;
import com.usian.pojo.TbContent;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chen
 * @date 2021/1/11 - 20:09 - 星期一
 * @project usian_parent
 * @package com.usian.controller
 * @by GGbomd猪猪侠
 */
@RestController
@RequestMapping("/content")
public class ContentControllerWeb {

    @Autowired
    private ContentServiceFeign contentServiceFeign;

    /**
     * 根据分类查询内容
     * @param page 当前页
     * @param rows 每页显示几条数据
     * @param categoryId 分类的id
     * @return
     */
    @RequestMapping("/selectTbContentAllByCategoryId")
    public Result selectTbContentAllByCategoryId(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "30") Integer rows, Long categoryId){
        PageResult pageResult = contentServiceFeign.selectTbContentAllByCategoryId(page, rows, categoryId);
        if (pageResult != null && pageResult.getResult().size() > 0) {
            return Result.ok(pageResult);
        }
        return Result.error("查无结果");
    }

    /**
     * 根据分类添加内容
     * @param tbContent
     * @return
     */
    @RequestMapping("/insertTbContent")
    public Result insertTbContent(TbContent tbContent){
        Integer num = contentServiceFeign.insertTbContent(tbContent);
        if (num != null) {
            return Result.ok();
        }
        return Result.error("添加失败");
    }

    /**
     *  删除分类下的内容
     * @param id
     * @return
     */
    @RequestMapping("/deleteContentByIds")
    public Result deleteContentByIds(@RequestParam Long ids){
        Integer num = contentServiceFeign.deleteContentByIds(ids);
        if (num != null) {
            return Result.ok();
        }
        return Result.error("删除失败");
    }
}
